package com.haoxin.ai_course.modules.course.controller;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.haoxin.ai_course.common.annotation.SysLog;
import com.haoxin.ai_course.common.base.AbstractController;
import com.haoxin.ai_course.common.utils.DateUtil;
import com.haoxin.ai_course.common.utils.EasyExcelUtil;
import com.haoxin.ai_course.common.utils.R;
import com.haoxin.ai_course.modules.course.entity.AcArticleCount;
import com.haoxin.ai_course.modules.course.entity.AcStatisticsArticle;
import com.haoxin.ai_course.modules.course.entity.VO.AcStatisticsArticleExcelVO;
import com.haoxin.ai_course.modules.course.entity.VO.AcStatisticsCourseDetailVO;
import com.haoxin.ai_course.modules.course.service.AcArticleCountService;
import com.haoxin.ai_course.modules.course.service.AcStatisticsArticleService;

import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import ma.glasnost.orika.MapperFacade;



/**
 * 文章统计表
 * 
 * @author xingxiangguo
 * @email bugcn@qq.com
 * @date 2022-07-20 16:05:43
 */
@RestController
@AllArgsConstructor
@RequestMapping("/course/acstatisticsarticle")
public class AcStatisticsArticleController  extends AbstractController {
    private final  AcStatisticsArticleService acStatisticsArticleService;
    private final  AcArticleCountService acArticleCountService;
    private final  MapperFacade mapperFacade;
//    /**
//     * 列表
//     */
//    @RequestMapping("/list")
//    @RequiresPermissions("course:acstatisticsarticle:list")
//    public R list(@RequestParam Map<String, Object> params){
//        //查询列表数据
//        QueryWrapper<AcStatisticsArticle> queryWrapper = new QueryWrapper<>();
//        IPage<AcStatisticsArticle> sysConfigList = acStatisticsArticleService.page(mpPageConvert.<AcStatisticsArticle>pageParamConvert(params),queryWrapper);
//        return R.ok().put("page", mpPageConvert.pageValueConvert(sysConfigList));
//    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("course:acstatisticsarticle:list")
    public R list(@RequestParam Map<String, Object> params){
    	//查询列表数据
    	QueryWrapper<AcArticleCount> queryWrapper = new QueryWrapper<>();
    	IPage<AcArticleCount> sysConfigList = acArticleCountService.page(mpPageConvert.<AcArticleCount>pageParamConvert(params),queryWrapper);
    	return R.ok().put("page", mpPageConvert.pageValueConvert(sysConfigList));
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("course:acstatisticsarticle:info")
    public R info(@PathVariable("id") Integer id){
        return R.ok().put("acStatisticsArticle", acStatisticsArticleService.getById(id));
    }


    /**
     * 新增文章统计表
     */
    @SysLog("新增文章统计表数据")
    @RequestMapping("/save")
    @RequiresPermissions("course:acstatisticsarticle:save")
    public R save(@RequestBody AcStatisticsArticle acStatisticsArticle){
        acStatisticsArticleService.save(acStatisticsArticle);
        return R.ok();
    }


    /**
     * 修改
     */
    @SysLog("修改文章统计表数据")
    @RequestMapping("/update")
    @RequiresPermissions("course:acstatisticsarticle:update")
    public R update(@RequestBody AcStatisticsArticle acStatisticsArticle){
		acStatisticsArticleService.updateById(acStatisticsArticle);
        return R.ok();
    }

    @GetMapping("exportExcel")
    @ApiOperation("导出excel")
   	public void exportExcel(HttpServletResponse response) {
   		List<AcArticleCount> acStatisticsArticle = acArticleCountService.list();
   		List<AcStatisticsArticleExcelVO> acStatisticsAnswerVOList=mapperFacade.mapAsList(acStatisticsArticle, AcStatisticsArticleExcelVO.class);
   		try {
   			EasyExcelUtil.exprotExcel(response, acStatisticsAnswerVOList, "文章统计表-" +DateUtil.localDateTimeFormat(LocalDateTime.now(), "yyyyMMdd"),
   			"文章统计表" ,
   			AcStatisticsArticleExcelVO.class);
   		} catch (Exception e) {
   			e.printStackTrace();
   		}
   	}
    /**
     * 删除
     */
    @SysLog("删除文章统计表数据")
    @RequestMapping("/delete")
    @RequiresPermissions("course:acstatisticsarticle:delete")
    public R delete(@RequestBody Integer[] ids){
		acStatisticsArticleService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
	
}
